﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using ASPItalia.ModelVirtualCasting.WPF.Common;
using ASPItalia.ModelVirtualCasting.WPF.Models;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace ASPItalia.ModelVirtualCasting.WPF.Converter
{
    public class SelectOneOrDefault: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollectionEx<Multimedia> modelMultimendiaCollection  = value as ObservableCollectionEx<Multimedia>;


            if (modelMultimendiaCollection != null && modelMultimendiaCollection.Count > 0)
            {
                var image = modelMultimendiaCollection.OfType<MultimediaImage>().FirstOrDefault();
                if (image != null) return image.ImageSource;
            }
            
                //TODO default
                BitmapImage bi3 = new BitmapImage();
                bi3.BeginInit();
                bi3.UriSource = new Uri("/SampleData/Images/FakeModel (1).jpg", UriKind.Relative);
                bi3.EndInit();

                return bi3;
          
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
